package com.ruoyi.log;

import ch.qos.logback.classic.Level;
import ch.qos.logback.classic.spi.ILoggingEvent;
import ch.qos.logback.core.filter.Filter;
import ch.qos.logback.core.spi.FilterReply;

/**
 * @author chenjc
 * @since 2021/03/12 10:12
 */
public class InfoClassFilter extends Filter<ILoggingEvent> {

    public static final String INFO_INVALIDATION = "invalidation sessions...";
    public static final String INFO_SESSION = "Finished invalidation session. No sessions were stopped.";
    public static final String INFO_CONFIG = "Using existing EHCache named [sys-config]";
    public static final String INFO_DICT = "Using existing EHCache named [sys-dict]";

    @Override
    public FilterReply decide(ILoggingEvent iLoggingEvent) {
        if (iLoggingEvent.getLevel() == Level.INFO) {
            if (iLoggingEvent.getMessage().equals(INFO_DICT) ||
                    iLoggingEvent.getMessage().equals(INFO_CONFIG) ||
                    iLoggingEvent.getMessage().equals(INFO_SESSION) ||
                    iLoggingEvent.getMessage().equals(INFO_INVALIDATION)) {
                return FilterReply.DENY;
            }
            return FilterReply.ACCEPT;
        }
        return FilterReply.DENY;
    }
}
